package yzbx.personalwebsite.entityWeb;

import java.util.HashMap;
import java.util.Map;

/**
 * {@code @Author} zxm
 * {@code @Description} 前端富文本编译器的返回格式
 * {@code @Date} 2024/10/17/16:31
 * {@code @Version} 1.0
 * <p>
 * "errno": 0, // 注意：值是数字，不能是字符串
 * "data": {
 * "url": "xxx", // 图片 src ，必须
 * "alt": "yyy", // 图片描述文字，非必须
 * "href": "zzz" // 图片的链接，非必须
 * }
 * {
 * "errno": 1, // 只要不等于 0 就行
 * "message": "失败信息"
 * }
 */
public class WangImgResponse {

    public static Map<String, Object> setResponse(String url, String alt, String href, int errno, String message) {
        Map<String, String> data = new HashMap<String, String>();
        data.put("url", url);
        data.put("alt", alt);
        data.put("href", href);
        Map<String, Object> obj = new HashMap<String, Object>();
        obj.put("errno", errno);
        obj.put("data", data);
        obj.put("message", message);
        return obj;
    }

    public static Map<String, Object> setSimpleResponse(String url) {
        Map<String, String> data = new HashMap<String, String>();
        data.put("url", url);
        data.put("alt", "");
        data.put("href", "");
        Map<String, Object> obj = new HashMap<String, Object>();
        obj.put("errno", 0);
        obj.put("data", data);
        obj.put("message", "");
        return obj;
    }

    public static Map<String, Object> setFailResponse() {
        Map<String, Object> obj = new HashMap<String, Object>();
        obj.put("errno", 1);
        obj.put("message", "上传图片为空");
        return obj;
    }
}
